package com.hmall.api.config;

import com.hmall.api.fallback.ItemServiceClientFallback;
import com.hmall.common.utils.UserContext;
import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;

public class DefaultFeignLogLevel {
    @Bean
    public Logger.Level feignLoggerLevel(){
        return Logger.Level.NONE;
    }

    @Bean
    public RequestInterceptor feignInterceptor(){

        return new RequestInterceptor(){
            @Override
            public void apply(RequestTemplate requestTemplate) {
                String userId = UserContext.getUser().toString();
                if (userId != null){
                    requestTemplate.header("userId",userId);
                }
            }
        };
    }

    @Bean
    public ItemServiceClientFallback itemServiceClientFallback(){
        return new ItemServiceClientFallback();
    }
}
